package controls {
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
 
	public class Button extends MovieClip{
		static public const CLICK:String = "button_click"; 
		
		public var index:uint;
		
 		private var _main:Object;

		public function Button() {			
			_main = this;
			_main.buttonMode = true;
			_main.addEventListener(MouseEvent.ROLL_OVER, onRollOverHandler);
			_main.addEventListener(MouseEvent.ROLL_OUT, onRollOutHandler);
			_main.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDownHandler);
			_main.addEventListener(MouseEvent.CLICK, onClickHandler);			
		}

		private function onRollOverHandler($e : MouseEvent) : void {
			_main.gotoAndStop( "over" );
		}

		private function onRollOutHandler($e : MouseEvent) : void {
			_main.gotoAndStop( "up" );
		}		
		
		private function onMouseDownHandler($e : MouseEvent) : void {
			_main.gotoAndStop( "down" );
		}		
		
		private function onClickHandler($e : MouseEvent) : void {
			_main.gotoAndStop( "up" );
			dispatchEvent( new Event( CLICK ) );
		}
	}
}